package kr.hkit.powerjava.chapter22.work3.dao;

import java.util.HashMap;
import java.util.Map;

import kr.hkit.powerjava.chapter22.work3.vo.Department;

public class DepartmentImpl implements ItemDaoInterface<Department> {

	private HashMap<Integer, Department> dp = new HashMap<>();
	
	
	public DepartmentImpl(HashMap<Integer, Department> dp) {
		this.dp = dp;
	}

	@Override
	public void addItem(Department item) {
		dp.put(item.getDeptNo(), item);
	}

	@Override
	public void delItem(Department item) {
		dp.remove(item.getDeptNo());
	}

	@Override
	public void updateItem(Department item) {
		if(searchItem(item)){
			dp.put(item.getDeptNo(), item);
		}else{
			System.out.println("수정 실패");
		}
	}

	@Override
	public boolean searchItem(Department item) {
		return dp.containsKey(item.getDeptNo());
	}

	@Override
	public void prnItems() {
		prnHeader();
		for (Map.Entry<Integer, Department> d: dp.entrySet()) {
			System.out.println(d.getValue());
		}
		
	}
	private void prnHeader() {
		String str = String
		.format("%3s\t%4s\t%3s", "학과번호", "학과명", "위치");
		System.out.println(str);
		System.out.println("---------------------");
	}

}
